package xzy.com.config.mybatisplus;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

/**
 * 
* @Title: MyMetaObjectHandler
* @Description: Mybatis-Plus更新时间与创建时间配置
* @author: liyang
* @date 2020年11月25日 上午10:33:01
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        //在执行增加操作的时候,不仅仅要给createTime赋值,而且要给modifiedTime赋值
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
